package net.csdn.business.discuss.api.service.impl;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import net.csdn.business.discuss.api.event.DiscussActivityApplicationEvent;
import net.csdn.business.discuss.api.mapper.DiscussActivityMapper;
import net.csdn.business.discuss.api.model.dto.DiscussActivityEventDTO;
import net.csdn.business.discuss.api.model.dto.NewDiscussActivityDTO;
import net.csdn.business.discuss.api.model.entity.DiscussActivity;
import net.csdn.business.discuss.api.service.IDiscussActivityService;
import org.springframework.beans.BeanUtils;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName DiscussActivityServiceImpl
 * @Description TODO
 * @Author zhangyl
 * @Date 2023/7/22 12:01
 */
@Service
@RequiredArgsConstructor
public class DiscussActivityServiceImpl extends ServiceImpl<DiscussActivityMapper, DiscussActivity> implements IDiscussActivityService {

    private final ApplicationEventPublisher applicationEventPublisher;

    @Override
    public void sendDiscussActivity(DiscussActivityEventDTO eventDTO) {
        // 发布事件
        DiscussActivityApplicationEvent event=new DiscussActivityApplicationEvent(eventDTO);
        applicationEventPublisher.publishEvent(event);
    }

    @Override
    public Integer saveDiscussActivity(NewDiscussActivityDTO params) {
        DiscussActivity discussActivity=new DiscussActivity();
        BeanUtils.copyProperties(params,discussActivity);
        String id= IdUtil.fastSimpleUUID();
        discussActivity.setObjectId(id);
        return baseMapper.insert(discussActivity);
    }

    /**
     * @Author zhangyl
     * @Description 查询discuss最近参与讨论的100个用户信息
     * @Date 14:18 2023/7/24
     * @Param
     * @return
     **/
    public List<String> selectRecentRelateUser(String discussId){
        return baseMapper.selectRecentRelateUser(discussId);
    }

    @Override
    public List<String> selectRelateUser(String discussId) {
        return baseMapper.selectRelateUser(discussId);
    }
}
